<?php
class C_checklist extends CI_Controller {
	function __construct(){
		parent::__construct();
		checkLogin();
		$this->load->model('m_checklist');
	}
	function index(){
		$task = secure_post('task');
		switch($task){
			case 'LIST' :
				$this->_list();
				break;
			case 'INSERT' :
				$this->_insert();
				break;
			case 'UPDATE' :
				$this->_update();
				break;
			case 'DELETE' :
				$this->_delete();
				break;
			default :
				$this->load->view('v_checklist');
		}
	}
	
	function _list(){
		$data['page'] = numeric_post("page");
		$data['rows'] = numeric_post("rows");
		$data['checklist_name'] = nosql_post("checklist_name");
		echo $this->m_checklist->_list($data);
	}
	
	function _insert(){
		$data = array(
			'checklist_name' => $this->input->post('checklist_name'), 
			  
			'checklist_active'=> 'y',
			'checklist_insert_user'	=>$_SESSION[SESSION_USERNAMA],
			'checklist_insert_date'=> date("Y-m-d h:i:s")
		);
		$this->m_checklist->_insert($data);
		echo 1;
	}
	
	function _update(){
		$checklist_id = $this->input->post('checklist_id');
		$data = array(
			'checklist_name' => $this->input->post('checklist_name'), 
			
			'checklist_update_user'	=>$_SESSION[SESSION_USERNAMA],
			'checklist_update_date'=> date("Y-m-d h:i:s")
		);
		$this->m_checklist->_update($data,$checklist_id);
		echo 1;
 	}
	
	function _delete(){
		$checklist_id= $this->input->post('checklist_id');
		$data = array(
			'checklist_active' => 'n'
		);
		$this->m_checklist->_delete($data,$checklist_id);
		echo 1;
	}
}